<template>
  <div class="mod-config">
    <table-view ref="view"
                :searchAttrs="searchAttrs"
                :primaryKey="primaryKey"
                :listApiName="listApiName"
                :deleteApiName="deleteApiName"
                :saveAuthName="saveAuthName"
                :deleteAuthName="deleteAuthName"
                :showAttrs="showAttrs"
                :multiAdd='true'
    >
    </table-view>
    <productinfo-add-or-update v-if="productInfoVisible" ref="productInfo"></productinfo-add-or-update>
    <client-info-add-or-update v-if="clientInfoVisible" ref="clientInfo"></client-info-add-or-update>
    <deep-category-add-or-update v-if="deepCategoryInfoVisible" ref="deepCategory" ></deep-category-add-or-update>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './deepsemifinished-add-or-update'
  import tableView from '@/components/tableView'
  import basicMixins from '@/utils/commonViewMixins'
  import ProductinfoAddOrUpdate from '@/views/modules/product/productinfo-add-or-update'
  import ClientInfoAddOrUpdate from '@/views/modules/client/clientinfo-add-or-update'
  import DeepCategoryAddOrUpdate from '@/views/modules/deep/deepcategory-add-or-update'

  export default {
    mixins: [basicMixins],
    data () {
      return {
        tableListData: [{
          orderDetailId: '',
          productId: '',
          productNumber: 0,
          productSource: 1,
          clientId: '',
          remark: ''
        }],
        dataForm: {},
        searchAttrs: {
          orderDetailId: {
            type: 'autoComplete',
            placeholder: '请输入订单编号',
            querySearchApiName: 'orderApi/getDeepOrderDetailList'
          },
          productId: {
            type: 'autoComplete',
            placeholder: '请输入产品名称',
            querySearchApiName: 'productApi/getProductInfoList'
          },
          clientId: {
            label: '客户名称',
            clearable: true,
            type: 'autoComplete',
            placeholder: '请输入客户名称',
            querySearchApiName: 'clientApi/getClientList'
          },
          dateTimeRange: {
            type: 'date',
            dateType: 'daterange',
            clearable: true
          }
        },
        productInfoVisible: false,
        clientInfoVisible: false,
        deepCategoryInfoVisible: false,
        primaryKey: 'id',
        listApiName: 'deepApi/listDeepSemiFinished',
        deleteApiName: 'deepApi/deleteDeepSemiFinished',
        saveAuthName: 'deep:deepstatementaccount:save',
        deleteAuthName: 'deep:deepstatementaccount:delete',
        showAttrs:{
          orderNo:{
            label: '订单编号',
            width: 200
          },
          productNo:{
            label: '产品名称',
            width: 150
          },
          productNumber:{
            label: '半成品数量',
            width: 150
          },
          clientName:{
            label: '客户名称',
            width:150
          },
          productSource:{
            label: '产品来源',
            type: 'radio',
            items: [
              {value: 0, text: '三和'},
              {value: 1, text: '来料加工', tagType: 'warning'}
            ],
            width: 100
          },
          putInTime:{
            label: '入库时间',
            type: 'date',
            width: 120
          },
          remark:{
            label:'备注'
          }
        },
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        }
      }
    },
    components: {
      ProductinfoAddOrUpdate,
      ClientInfoAddOrUpdate,
      DeepCategoryAddOrUpdate,
      AddOrUpdate,
      tableView
    },
    methods: {
      openProductInfoDialog(cb) {
        this.productInfoVisible = true
        this.$nextTick(() => {
          if (!this.R.isNil(this.$refs.productInfo)) {
            this.$refs.productInfo.init(null, {status: 1}, cb)
          }
        })
      },
      openClientInfoDialog(cb) {
        this.clientInfoVisible = true
        this.$nextTick(() => {
          if (!this.R.isNil(this.$refs.clientInfo)) {
            this.$refs.clientInfo.init(null, {status: 1}, cb)
          }
        })
      },
      openDeepCategoryInfoDialog(cb){
        this.deepCategoryInfoVisible = true
        this.$nextTick(() => {
          if (!this.R.isNil(this.$refs.deepCategory)) {
            this.$refs.deepCategory.init(null, {status: 1}, cb)
          }
        })
      }
    }
  }
</script>
